Sub BestRankPrint()
' Connect to Sales Rank Spreadsheet, find best rank and print it
Dim cnxn As New ADODB.Connection
Dim rst1 As ADODB.Recordset
Dim bestRank As Double
Dim currentRank As Double

' Connect to Excel data source
cnxn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
     "Data Source=C:\APP Example Files\BookSalesRank.xls;" & _
     "Extended Properties=Excel 8.0;"
' Open a read-only recordset based on the Excel source file
Set rst1 = New ADODB.Recordset
rst1.CursorType = adOpenForwardOnly
rst1.LockType = adLockReadOnly
rst1.Open "ranks", cnxn, , , adCmdTable

'Find best sales rank
bestRank = 3000000
Do Until rst1.EOF
     currentRank = rst1.Fields(1)
     If currentRank < bestRank Then
          bestRank = currentRank
     End If
rst1.MoveNext
Loop

Debug.Print bestRank

End Sub
